<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Index_Index extends Controller_Index_Base
{
    public function action_index()
    {              
        $content = new View('index/index/index_tpl'); 
        $content->categories = ORM::factory('category')->get_categories();       
        $this->print_template('Поиск отповых поставщиков', $content); 
    }
    
    public function action_search()
    {
        $query  = strip_tags($this->request->param('query'));
        $page   = $this->request->param('page') ? $this->request->param('page') : 1;
        
        $result = ORM::factory('good')->search($query, $page);
        Model_Stat::update_goods_views($result['result']);
        
        $suppliers = Model_Supplier::get_suppliers_by_goods($result['result']);
        Model_Stat::update_suppliers_views($suppliers); 
        
        $content = new View('index/index/search_tpl');
        
        $content->suppliers    = $suppliers;
        $content->query        = $query;
        $content->result       = $result['result'];
        $content->count        = $result['count'];
        $content->pagination = array(
            'page'     => $page,
            'per_page' => ORM::factory('good')->get_goods_per_page(),
        );
        $this->print_template("Поиск: " . $query, $content);        
    } 
} 
